import { request } from "../../request/index"
import { showModal,chooseAddress,showToast } from "../../utils/tools"
import regeneratorRuntime from '../../lib/runtime/runtime';

Page({

  /**
   * 页面的初始数据
   */
  data: { 
    goodsList:[],
    isFouncs:false,
    inputValue:""
  }, 
  Timenum: -1,
   
  // 搜索框
   handInputValue(e){ 
    let {value} = e.detail  
    this.data.inputValue = value
    let  {inputValue} = this.data 

    if(inputValue.trim()){  // 如果值存在
      this.setData({
        isFouncs:true
      })
    }else{
      this.setData({
        isFouncs:false,
        goodsList:[]
      })
    }
    // 防抖处理
    clearTimeout(this.Timenum) 
    this.Timenum = setTimeout(()=>{
      this.search(inputValue)
    },1000)
   
  },

  // 搜索库数据
  async search(query){
    const res = await request({ url:"/goods/qsearch",data:{query} })  
    if(res.length == 0){
      await  showToast({title: '搜索内容不存在',  duration:1000 })
    } 
    this.setData({
      goodsList:res
    })
  },

  // 单击取消
  btnCancel(){

    this.setData({
      goodsList:[], 
      inputValue:""
    })
  }
 
})